<%@ page language="java" pageEncoding="utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath =
            request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

%>
<!DOCTYPE html>
<head>
    <base href="<%=basePath %>">
    <title>添加栏目</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet"
          href="static/admin/css/bootstrap/css/bootstrap-3-3-5.min.css">
    <link rel="stylesheet" type="text/css" href="static/util/plugins/layui/css/layui.css"/>
    <script type="text/javascript" src="static/js/jquery1-11-3.min.js"></script>
    <script type="text/javascript" src="static/util/plugins/layui/layui.js"></script>
    <script type="text/javascript">
        var layer;
        function formsubmit() {
            var na = document.getElementById("catalogName").value;
            var nc = document.getElementById("catalogCode").value;
            if (na == "") {
                layer.msg("栏目名称不能为空!", {time: 3000});
                return false;
            }
            if (nc == "") {
                layer.msg("栏目标识号不能为空!", {time: 3000});
                return false;
            }
            var ncrn = /^[a-zA-Z0-9_]{1,}$/;
            if (!ncrn.test(nc)) {
                layer.msg("栏目标识号不能含有中文!", {time: 3000});
                return false;
            }
            return true;
        }
        function ajaxSubSubmitForm(layerIndex) {
            if (formsubmit()) {
                $.ajax({
                    type: "post",
                    url: "admin/website/catalog/saveCatalog",
                    data: $("#catalogForm").serialize(),
                    success: function (result) {
                        if (result.success) {
                            window.parent.parentLayer.close(layerIndex);
                            //alert("刷新不起作用！");
                            window.location.reload(true);
                            //window.location.href = "admin/website/catalog/catalogTree?caid=" + result.data
                                //+ "&timeStr=" + Math.floor(Math.random() * 100000);
                            window.parent.parentLayer.msg("保存成功!", {time: 3000});
                        } else {
                            layer.msg(result.message, {time: 3000});
                        }
                    }
                });
            }
        }
    </script>
</head>

<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-1"></div>
        <div class="col-md-10">
            <div class="panel panel-success" style="margin-top:30px;">
                <div class="panel-heading">栏目编辑</div>
                <div class="panel-body">
                    <form class=".form-horizontal" id="catalogForm">
                        <div class="form-group">
                            <input type="hidden" name="catalogInfo.id" value="${catalogInfo.id}"/>
                            <input type="hidden" name="catalogInfo.orderId" value="${catalogInfo.orderId}"/>
                        </div>
                        <div class="form-group" style="height:40px;">
                            <label for="catalogName" class="col-sm-2 control-label">栏目标识号</label>
                            <div class="col-sm-10">
                                <%
                                    String actionType = (String) request.getAttribute("actionType");
                                    if (actionType != null && actionType.equals("update")) {
                                %>
                                <input type="text" class="form-control" id="catalogCode" readonly="true"
                                       name="catalogInfo.cataCode" value="${catalogInfo.cataCode}"/>
                                <%
                                } else {
                                %>
                                <input type="text" class="form-control" id="catalogCode"
                                       required="required" onkeyup="onlyEng()"
                                       placeholder="栏目标识号 如（catalog-001）"
                                       name="catalogInfo.cataCode" value="${catalogInfo.cataCode}"/>
                                <%}%>
                            </div>
                        </div>
                        <div class="form-group" style="height:40px;">
                            <label for="catalogName" class="col-sm-2 control-label">栏目名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="catalogName" required="required"
                                       placeholder="栏目名称" name="catalogInfo.name" value="${catalogInfo.name}"/>
                            </div>
                        </div>
                        <div class="form-group" style="height:40px;">
                            <label class="col-sm-2 control-label">栏目类型</label>
                            <div class="col-sm-10">
                                <select class="form-control" id="catatype" name="catalogInfo.type">
                                    <option value="N" selected>新闻资讯</option>
                                    <option value="A">文学文字</option>
                                    <option value="P">娱乐搞笑</option>
                                    <option value="O">其他栏目</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group" style="height:40px;">
                            <label class="col-sm-2 control-label">显示类型</label>
                            <div class="col-sm-10">
                                <select class="form-control" id="catashowtype" name="catalogInfo.showType">
                                    <option value="A" selected>文章列表</option>
                                    <option value="H">图片横排</option>
                                    <option value="V">图片纵排</option>
                                    <option value="S">静态页面</option>
                                    <option value="O">其他方式</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group" style="height:40px;">
                            <label class="col-sm-2 control-label">是否显示</label>
                            <div class="col-sm-10">
                                <label class="form-control">
                                    <input type="radio" name="catalogInfo.isShow" checked value="Y"/>是
                                    <input type="radio" name="catalogInfo.isShow" value="N"/>否
                                </label>
                            </div>
                        </div>
                        <div class="from-group" style="height:40px;">
                            <label class="col-sm-2 control-label">备注</label>
                            <div class="col-sm-10">
									<textarea class="form-control" style="max-width: 100%"
                                              name="catalogInfo.remark">${catalogInfo.remark}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"></label>
                            <div class="col-sm-10" style="height:80px">
                            </div>
                        </div>
                        <div class="form-group" style="text-align:center;">
                            <%
                                if (actionType != null && actionType.equalsIgnoreCase("update")) {
                            %>
                            <input type="hidden" id="parentId" name="catalogInfo.parentId"
                                   value="${catalogInfo.parentId}"/>
                            <input type="hidden" name="actionType" value="update"/>
                            <%
                                }else{
                                    %>
                            <input type="hidden" id="parentId" name="catalogInfo.parentId"
                                   value="${parentId}"/>
                            <input type="hidden" name="actionType" value="add"/>
                                    <%
                                }
                            %>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-md-1"></div>
    </div>
</div>
</body>
<script type="text/javascript">
    $(function () {
        layui.use('layer', function () {
            layer = layui.layer;
            layer.config({skin: 'layui-layer-molv',});
        });
        <%
            if (actionType != null && actionType.equals("update")) {
        %>
        $("#catatype option[value='N']").removeAttr("selected");
        $("#catatype option[value='${catalogInfo.type}']").attr("selected", "selected");
        $("#catashowtype option[value='A']").removeAttr("selected");
        $("#catashowtype option[value='${catalogInfo.showType}']").attr("selected", "selected");
        <%}%>
    });
</script>
<script language=javascript>
    var keylastuplength = 0;
    function onlyEng()  //禁止用户输入中文或中文符号的js
    {
        var thisval = document.getElementById('catalogCode').value;
        var cArr = thisval.match(/[^\x00-\xff]/ig);
        var lengthstr = thisval.length + (cArr == null ? 0 : cArr.length);
        if (thisval.length != lengthstr) {
            document.getElementById('catalogCode').value
                = document.getElementById('catalogCode').value.substring(0, keylastuplength);
        } else {
            keylastuplength = thisval.length;
        }
    }
</script>
</html>
